<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改医生信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layui/layuiAdmin/css/admin.css" media="all">
    <style>
        .st{
            width: 270px!important;
        }
        .layui-form-label{
            width: 120px!important;
        }
        .xinghao{
            color: red!important;
        }
    </style>
</head>
<body>

<!--表单-->
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">

    <div class="layui-form-item">
        <label class="layui-form-label">病例名称<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <input type="text" name="casename" lay-verify="required|casename" placeholder="请输入病例名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">探讨主题<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <input maxlength="20" type="text" name="researchtopic" lay-verify="required|researchtopic" placeholder="请输入探讨主题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">探讨持续时间<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <input type="text" name="continuetime" lay-verify="required|duration" placeholder="请输入探讨持续时间（1~99小时）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收费类型<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <select name="feeType" lay-verify="required">
                <option value="">请选择</option>
                <option value="收费">收费</option>
                <option value="给予奖励">给予奖励</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">探讨费用<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <input type="text" name="charge" lay-verify="required|money" placeholder="请输入探讨费用（1~999）" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">探讨说明<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <input maxlength="200" type="text" name="researchnote"  lay-verify="required" placeholder="请输入探讨说明（1~200）" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">日期范围</label>
            <div class="layui-inline" id="test6">
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" id="test-startDate-1" class="layui-input" placeholder="开始日期">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" id="test-endDate-1" class="layui-input" placeholder="结束日期">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">主持人<span class="xinghao">*</span></label>
        <div class="layui-input-inline st">
            <input type="text" name="host" lay-verify="required|host" placeholder="请选择主持人" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
    </div>
</div>

<script src="../../../layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layui/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'layer', 'form','layedit','laydate'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,layedit = layui.layedit;

        //日期范围
        laydate.render({
            elem: '#test6'
            //设置开始日期、日期日期的 input 选择器
            //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
            ,type: 'datetime'
            ,range: ['#test-startDate-1', '#test-endDate-1']
        });


        $(document).ready(function() {
            $('#LAY-user-front-submit').on('click', function() {
                // 收集表单数据
                var formData = {
                    registrationtime: $('#test-startDate-1').val(),
                    registrationendtime: $('#test-endDate-1').val(),
                    host: $('input[name="host"]').val(),
                    casename: $('input[name="casename"]').val(),
                    researchtopic: $('input[name="researchtopic"]').val(),
                    continuetime: $('input[name="continuetime"]').val(),
                    researchnote: $('input[name="researchnote"]').val(),
                    chargetype: $('select[name="feeType"]').val(),
                    charge: $('input[name="charge"]').val(),
                };
                    console.log("具体",formData);
                // 发起AJAX POST请求
                $.ajax({
                    url: "/caseManager/add", // 确保这个URL与你的后端路由匹配
                    type: "post",
                    dataType: "json",
                    contentType: "application/json;charset=utf-8", // 设置请求内容类型
                    data: JSON.stringify(formData), // 发送收集到的表单数据
                    success: function(res) {
                        console.log(res)
                    },
                    error: function(xhr, status, error) {
                        // 处理错误的回调
                        console.error("AJAX error: " + error);
                    }
                });
            });
        });
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //自定义验证规则
        form.verify({
            // startTime: function(value, item){ //value：表单的值、item：表单的DOM对象
            //     if(!new Date(value.replace(/-/g, "/")).getTime()){
            //         return '请选择有效的报名时间';
            //     }
            // },
            // endTime: function(value, item){
            //     if(!new Date(value.replace(/-/g, "/")).getTime()){
            //         return '请选择有效的报名结束时间';
            //     }
            //     var startTimeStr = laydate.elem('#startTime').value;
            //     if(value < startTimeStr){
            //         return '报名结束时间不能早于报名时间';
            //     }
            // },

            money: function(value){
                if(!new RegExp("^[1-9][0-9]{0,2}$").test(value)){
                    return '请输入1~999的数字！';
                }
            },
            duration: function(value){
                if (value.length===0||value===''){
                    return '探讨持续时间不能为空';
                }
          },
            researchtopic: function(value){
                if (value.length===0||value===''){
                    return '探讨主题不能为空';
                }
            },
            casename: function(value){
                if (value.length===0||value===''){
                    return '病例名称不为空';
                }
            },
            host: function(value){
                if (value.length===0||value===''){
                    return '病例名称不为空';
                }
            },

        });

    })
</script>
</body>
</html>